﻿// <copyright file="Log.cs" company="Ecole Normale Supérieure">
// Released under GPLv2
// </copyright>
// <summary>Contains the Log class.</summary>

namespace Sqwarea.Persistence
{
    using System;
    using System.Drawing;
    using System.Runtime.Serialization;

    /// <summary>
    /// List of different events you can have in a log event
    /// </summary>
    public enum LogKind
    {
        /// <summary>
        /// Square lost by default of connexity
        /// </summary>
        ConnexityLoss = 0,

        /// <summary>
        /// Square lost by a direct attack
        /// </summary>
        AttackedLoss = 1,

        /// <summary>
        /// You successfully defended this square ;-)
        /// </summary>
        AttackedWin = 2,

        /// <summary>
        /// Sorry, you attacked this square but you did not won.
        /// </summary>
        AttackingLoss = 3,

        /// <summary>
        /// You won this battle, this square is now neutral.
        /// </summary>
        AttackingWin = 4,

        /// <summary>
        /// You won this battle and got this square !
        /// </summary>
        AttackingWinGot = 5,

        /// <summary>
        /// You lost your previous king and died. You have a new king.
        /// </summary>
        AttackedKingLoss = 6,

        /// <summary>
        /// Your king has fought a thought battle... but he survived.
        /// </summary>
        AttackedKingWin = 7,

        /// <summary>
        /// You have killed a king ! Congratulations ! 
        /// </summary>
        KingKilled = 8,

        /// <summary>
        /// You fought a king, but he was too strong and you lost the battle.
        /// </summary>
        KingNotKilled = 9,

        /// <summary>
        /// You have successfully send troops in one of your cases.
        /// </summary>
        IncreaseTroops = 10
    } 

    /// <summary>
    /// Log class : contain a log element.
    /// </summary>
    [DataContract]
    public class Log
    {
        /// <summary>
        /// Initializes a new instance of the Log class.
        /// sets Read to false and Date to UtcNow
        /// </summary>
        /// <param name="kingId">The king to who the log is sent</param>
        /// <param name="otherKingId">The other king involved in the event</param>
        /// <param name="kind">The kind of log</param>
        /// <param name="position">The position of the square involved in the event</param>
        public Log(long kingId, long otherKingId, LogKind kind, Point position)
        {
            KingId = kingId;
            OtherKingId = otherKingId;
            Kind = kind;
            Position = position;
            Read = false;
            Date = DateTimeOffset.UtcNow;
            UniqueId = Tools.RandId();
        }

        /// <summary>
        /// Gets or sets the king who receives the message.
        /// </summary>
        [DataMember]
        public long KingId { get; set; }

        /// <summary>
        /// Gets or sets the other king involved, if not the it is 0.
        /// </summary>
        [DataMember]
        public long OtherKingId { get; set; }

        /// <summary>
        /// Gets or sets the log event kind.
        /// </summary>
        [DataMember]
        public LogKind Kind { get; set; }
        
        /// <summary>
        /// Gets or sets the square concerned by the log event
        /// </summary>
        [DataMember]
        public Point Position { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether or not the Log has been readen
        /// </summary>
        [DataMember]
        public bool Read { get; set; }

        /// <summary>
        /// Gets or sets the date at which the log has been emitted
        /// </summary>
        [DataMember]
        public DateTimeOffset Date { get; set; }

        /// <summary>
        /// Gets the combinaison of 6 random characters linked to this log
        /// allows to make sure that the log is "uniquely" defined by it's KingId, Date and UniqueId
        /// </summary>
        [DataMember]
        public string UniqueId { get; private set; }
    }
}
